angular.module("myKitchen")
.controller("classifyController",function($scope,$state,$timeout,classifyService){
	classifyService.getfirstItems(function(res){
		// console.log(res.data);
		$scope.recommendItem = res.data;
	});
	classifyService.getsecondItems(function(res){
		// console.log(res.data);
		$scope.productList = res.data;
		$scope.changeClassifyItem = function(){
			$scope.id = this.classList.id;
			// console.log(this.classList);
			$scope.data9=[];
			$scope.data9.push(this.classList);
			for (var i = 0; i < res.data.length; i++) {
				if (res.data[i].parentId==$scope.id) {
					$scope.data9.push(res.data[i]);
				};
			};
		}
	});

	$scope.dataArr=function(name){	
		classifyService.dataArr(name);
	}

	$scope.getItemsData = function(parentId){
		// console.log(parentId);
		// 跳转到classifyItemList.html页面,并传递参数 parentId
		$state.go("classifyItemList",{parentId:parentId});
	}

})
.controller("classifyThirdController",function($scope,$state,$stateParams,classifyService){
	// 接收参数
	$scope.parentId = $stateParams.parentId;
	classifyService.getThirdItems($scope.parentId,function(res){
		// console.log(res.data.categories);
		$scope.thirdItemlist = res.data.categories;
	});
		
	$scope.title=classifyService.getdataArr()[0];

	// 点击加入购物车
	$scope.count = 0;
	$scope.classify_addToCart = function(Item){	
		$scope.count += 1; 
		// $scope.Items.push(Item);
		Item.cnt = Item.cnt ? (Item.cnt+1) : 1;
		classifyService.classifyCart(Item);
	}

// -------iscroll----暂时无法使用----------------------------------------------------
/*	var myScroll;
function loaded () {
	myScroll = new IScroll('#wrapper', {
		scrollbars: true,
		mouseWheel: true,
		interactiveScrollbars: true,
		shrinkScrollbars: 'scale',
		fadeScrollbars: true
	});
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, isPassive() ? {
	capture: false,
	passive: false
} : false);*/
// ---------------------------------------------------
})
.config(function($stateProvider,$urlRouterProvider){
	 // 点击分类页右侧二级菜单跳转
	$stateProvider.state("classifyItemList",{
		// 跳转到classifyItemList.html页面,并规定要接受的参数parentId
		url: "/classifyItemList/:parentId",
        // url: "/classifyItemList",
        templateUrl: "view/third/classifyItemList.html",
    })
})